package io.lkt.task.bus.service.impl;

import io.lkt.task.bus.mapper.MessageDictInfoMapper;
import io.lkt.task.bus.model.MessageDictInfo;
import io.lkt.task.bus.service.IMessageDictInfoService;
import io.lkt.task.bus.service.SysGzhService;
import io.lkt.task.model.PlatformSysInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageDictInfoServiceImpl implements IMessageDictInfoService {

    @Autowired
    private MessageDictInfoMapper messageDictInfoMapper;

//    @Value("${openMemberMenuUrl}")
//    private String openMemberMenuUrl;

    @Autowired
    private SysGzhService sysGzhService;

    @Override
    public MessageDictInfo getInfoByKey(String dictKey) {
        return messageDictInfoMapper.getInfoByKey(dictKey);
    }

    @Override
    public String getLinkMsgByKey(String dictKey,String frontDomain,String profile) {
        MessageDictInfo messageDictInfo= messageDictInfoMapper.getInfoByKey(dictKey);
        String msg="";
        if(messageDictInfo!=null){
            if(messageDictInfo.getDictType().equals(0)){
                PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);
                if(messageDictInfo.getLinkId().equals(7)){//开通会员
                    msg = "<a href='" + sysGzh.getOpenMemberMenuUrl() + "?mt=1'>" + messageDictInfo.getDictVal() + "</a>";
                }else if (messageDictInfo.getLinkId().equals(15)) {//领取优惠
                    msg = "<a href='" + sysGzh.getOpenMemberMenuUrl()  + "?mt=1&cardBag=1'>" + messageDictInfo.getDictVal() + "</a>";
                }else{
                    msg = "<a href='" + frontDomain + messageDictInfo.getLinkUrl() + "'>" + messageDictInfo.getDictVal() + "</a>";
                }
            }else if(messageDictInfo.getDictType().equals(1)) {
                msg="<a href=\"weixin://bizmsgmenu?msgmenucontent="+messageDictInfo.getDictText()+"&msgmenuid=2\">"+messageDictInfo.getDictVal()+"</a>";
            }
        }
        return msg;
    }

}
